/**
 * 
 */
package com.gi.profiler.listeners;

import android.content.ContentUris;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.provider.MediaStore;
import android.util.Log;

import com.gi.profiler.ProfilePreferencesActivity;
import com.gi.profiler.R;
import com.gi.profiler.VolumeActivity;
import com.gi.profiler.utils.DataConstants;

/**
 * @author Ruba
 * 
 */
public class ProfilePrefsListener implements OnPreferenceChangeListener, OnPreferenceClickListener {

    private ProfilePreferencesActivity prefsActivity;
    private final String LOG_NAME = getClass().getName();

    public ProfilePrefsListener(ProfilePreferencesActivity prefsActivity) {
	this.prefsActivity = prefsActivity;
    }

    public boolean onPreferenceClick(Preference preference) {
	Log.d(LOG_NAME, "Prefs Click Listener");
	String prefKey = preference.getKey();
	if (prefKey.equals(prefsActivity.getString(R.string.key_volume))) {
	    prefsActivity.startActivityForResult(new Intent(prefsActivity, VolumeActivity.class),
		    DataConstants.VOLUME_SETTINGS_REQUEST_CODE);
	}
	else if (prefKey.equals(prefsActivity.getString(R.string.key_ringtone))){
	    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
	    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,"My customised Title");
	    Uri uri = ContentUris.withAppendedId(
	    MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 1l);
	    // Don't show 'Silent'
	    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
	    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri);
	    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
	    prefsActivity.startActivityForResult( intent, 123);
	}
	return false;
    }

    public boolean onPreferenceChange(Preference preference, Object newValue) {
	// TODO Auto-generated method stub
	return false;
    }

}
